import requests,json,pytest,allure,logging
import read

class Test_jiekou():

    userid = None
    sessionId = None
    @pytest.mark.smoke
    @pytest.mark.login
    @pytest.mark.parametrize('data',read.read_json(r'D:\zhuanwu\zhuangao6_rk\yuekao_lianxi\Data\login.json'))
    def test_login_01(self,data):
        logging.info('log-login request')
        with allure.step('登录接口数据'):
            url = 'http://10.59.9.18/small/user/v1/login'
            json1 = {'phone':data.get('phone'),'pwd':data['pwd']}
            login = requests.post(url=url,json=json1)
        print(json.dumps(login.json(),indent=4,ensure_ascii=False))
        Test_jiekou.userid = login.json()['result']['userId']
        Test_jiekou.sessionId = login.json()['result']['sessionId']
        dy_message = login.json()['message']
        assert dy_message == data.get('expect'),f'断言错误，实际结果为{dy_message}'

    @pytest.mark.regression
    @pytest.mark.add
    def test_show_buycar(self):
        logging.info('log-look addcar request')
        with allure.step('查看购物车接口数据'):
            url = 'http://10.59.9.18/small/order/verify/v1/findShoppingCart'
        print(Test_jiekou.userid,'---',Test_jiekou.sessionId)
        headers = {'userId':str(self.userid),'sessionId':self.sessionId}
        add = requests.get(url=url,headers=headers)
        print(json.dumps(add.json(),indent=4,ensure_ascii=False))


